"""
@File    :   models.py
@Time    :   2024/02/07 22:57:47
@Author  :   Qrj
@Email   :   923207736@qq.com
@description   :   租户套餐数据模型
"""

from datetime import datetime

from sqlalchemy import (
    BigInteger,
    Boolean,
    Column,
    DateTime,
    Integer,
    String,
    UniqueConstraint,
)

from src.models.models import OrmBase


class TenantPackageMenuRel(OrmBase):
    """租户套餐与菜单(可用菜单)多对多关系中间表数据模型"""

    __tablename__ = "system_tenant_package_menu_rel"
    __table_args__ = (UniqueConstraint("tenant_package_id", "menu_id"),)

    id = Column(BigInteger(), primary_key=True, autoincrement=True, comment="主键")
    # 租户套餐ID(级联删除)
    tenant_package_id = Column(
        BigInteger(), nullable=False, index=True, comment="租户套餐ID"
    )
    # 菜单ID(级联删除)
    menu_id = Column(BigInteger(), nullable=False, comment="菜单ID")


class TenantPackage(OrmBase):
    """租户套餐模型"""

    __tablename__ = "system_tenant_package"

    id = Column(BigInteger(), primary_key=True, autoincrement=True, comment="主键")
    name = Column(String(100), nullable=False, unique=True, comment="套餐名称")
    status = Column(
        Boolean(), default=True, nullable=False, comment="状态"
    )  # (True正常 False停用)
    remark = Column(String(300), default="", nullable=False, comment="备注")
    create_datetime = Column(
        DateTime(), nullable=False, default=datetime.now, index=True, comment="创建时间"
    )
    update_datetime = Column(
        DateTime(),
        nullable=False,
        default=datetime.now,
        onupdate=datetime.now,
        index=True,
        comment="修改时间",
    )
    # 创建者用户名(级联删除)
    creator_username = Column(
        String(20), default="", nullable=False, comment="创建者用户名"
    )
    # 修改者用户名(级联删除)
    updater_username = Column(
        String(20), default="", nullable=False, comment="修改者用户名"
    )
    # 与菜单多对多关系(级联删除)
